package com.xzcedu.transformation;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * @author 徐州城
 * @version 1.0
 * 演示使用 InputStreamReader 转换流解决中文乱码问题
 * 将 FileInputStream 转成字符流 InputStreamReader，指定编码 gbk/utf-8
 */
public class InputStreamReader_ {
    public static void main(String[] args) throws Exception {

        String filePath = "e:\\f1.txt";
        //解读
        //1. new FileInputStream 转成了 new InputStreamReader
        //2. 指定编码 gbk
        InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath), "gbk");
        //3. 把 InputStreamReader 传入 BufferedReader
        BufferedReader br = new BufferedReader(isr);
        //将2 和 3 合在一起

        //读取
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println("读取的内容=" + s);
        }
        //5. 关闭外层流
        br.close();

    }
}
